'use strict';

define(['services'], function (services) {
    services.home.factory('LoginService', ['$http', function ($http) {
        return {
            login: function (account, password, success, failure) {
                $http.get('/rest/login', {
                    params: {account: account, password: password}
                }).success(function (data, status, headers, config) {
                    if (data.flag) {
                        if (success != null) {
                            success(data);
                        }
                    } else {
                        if (failure != null) {
                            failure(data.msg);
                        }
                    }
                });
            },
            logout: function (callback) {
                $http.get('/rest/logout', {
                    params: {}
                }).success(function (data, status, headers, config) {
                    if (callback != null) {
                        callback();
                    }
                });
            }
        }
    }]);
});